#encoding=utf-8
import sys,os
reload(sys)
sys.setdefaultencoding("utf8")
sys.path.append(os.path.abspath(os.path.join(os.getcwd(), os.pardir)))
import redis
from webconfig import redis_conf

if 'password' in redis_conf:
    global_redis_pool = redis.ConnectionPool(host=redis_conf["host"], port=redis_conf["port"],password=redis_conf['password'], db=0)
else:
    global_redis_pool = redis.ConnectionPool(host=redis_conf["host"], port=redis_conf["port"], db=0)
def get_redis():
    return redis.StrictRedis(connection_pool=global_redis_pool)


#测试在线统计
# rc = get_redis()
# print(rc.keys())
# for ii in rc.keys():
#     print(ii,'---',rc.get(ii))
# rc.flushdb()
# print('--start--')
# for ii in range(100):
#     #大厅
#     t_key="hall_online_%s"%ii
#     rc.set(t_key,1)
#     rc.expire(t_key,300)
#     #游戏
#     import random
#     if ii%2==0:
#         t_key="game_online_%s"%ii
#         rc.set(t_key,random.randint(0,2))
#         rc.expire(t_key,600)
# print(rc.keys())
# print('--end--')
# print(rc.keys('hall_online_*'))
# print(rc.keys('game_online_*'))
# print(rc.mget(['hall_online_1','hall_online_5','hall_online_11']))

# print('--start--')
# for ii in range(10):
#     #大厅
#     t_key="hall_online_%s"%ii
#     rc.set(t_key,1)
#     rc.expire(t_key,30)
#     #游戏
#     if ii%2==0:
#         t_key="game_online_%s"%ii
#         rc.set(t_key,ii%2)
#         rc.expire(t_key,60)
# print(rc.keys())
# print('--end--')
# print(rc.keys('hall_online_*'))
# print(rc.keys('game_online_*'))

